﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;// using Excel

namespace Excel1316AddIn01
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();//事先清空列表框中的所有项

            foreach (Excel.Worksheet wst in Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets)
                this.listBox1.Items.Add(wst.Name);// 比那里每一个工作表，把表名加入列表框
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // 单击列表框任一条目，Excel自动激活相应工作表
            Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets[listBox1.Text].Activate();
        }
    }
}
